#include <iostream>
#include <vector>
using namespace std;

//100%
class Solution1
{
  public:
	vector<int> twoSum(vector<int> &numbers, int target)
	{
		int re = -1;
		vector<int> myVector;
		for (int i = 0; i < numbers.size(); i++)
		{
			re = binarySearch(numbers, i + 1, numbers.size() - 1, target - numbers[i]);
			if (-1 != re)
			{
				myVector.push_back(i + 1);
				myVector.push_back(re + 1);
				return myVector;
			}
		}
	}
	int binarySearch(vector<int> &numbers, int s, int e, int target)
	{
		while (e >= s)
		{
			int mid = s + (e - s) / 2;
			if (numbers[mid] == target)
				return mid;
			if (numbers[mid] < target)
				s = mid + 1;
			else
				e = mid - 1;
		}
		return -1;
	}
};
//100.00%
class Solution
{
  public:
	vector<int> twoSum(vector<int> &numbers, int target)
	{
		int i = 0, j = numbers.size() - 1;
		while (i <= j)
		{
			if (numbers[i] + numbers[j] == target)
			{
				int re[2] = {i + 1, j + 1};
				vector<int> myVector(re, re + 2);
				return myVector;
			}
			if (numbers[i] + numbers[j] > target)
				j--;
			else
				i++;
		}
		int re[2] = {0, 0};
		vector<int> myVector(re, re + 2);
		return myVector;
	}
};

int main()
{
	int nums[7] = {3, 24, 50, 79, 88, 150, 345};
	int len = sizeof(nums) / sizeof(int);
	vector<int> myVector(nums, nums + len);
	myVector = Solution().twoSum(myVector, 200);
	len = myVector.size();
	for (int i = 0; i < len - 1; i++)
	{
		cout << myVector[i] << " ";
	}
	cout << myVector[len - 1] << endl;
	return 0;
}
